
#ifndef UTIL_H
#define UTIL_H

#include <time.h>
#include <string>
#include <iostream>
#include <stdarg.h>
#include <sys/timeb.h>

#ifdef _WIN32
#include <Windows.h>

class FontColor {
public:
	FontColor()	{
		m_hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	}

	void SetColor(int nColor)	{
		SetConsoleTextAttribute(m_hStdOut, nColor);
	}

	void UnSetColor()	{
		SetConsoleTextAttribute(m_hStdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	}

	~FontColor() { }
private:
	HANDLE	m_hStdOut;
};

enum COLOR_ENMU {
	FC_NORMAL,
	FC_GREEN = 0x0002 | 0x0008,
	FC_YELLOW = 0x0004 | 0x0002 | 0x0008,
	FC_RED = 0x0004 | 0x0008,
};

#else 

class FontColor {
public:
	FontColor()	{
		m_bUnset = true;
	}

	void SetColor(int nColor) {
		printf("\033[%dm", nColor % 10 + 30);
		m_bUnset = false;
	}

	void UnSetColor() {
		if (!m_bUnset) {
			printf("\033[0m");
			m_bUnset = true;
		}
	}

	~FontColor() {
		UnSetColor();
	}

private:
	bool	m_bUnset;
};

enum COLOR_ENMU {
	FC_NORMAL = 37,
	FC_GREEN = 32,
	FC_YELLOW = 33,
	FC_RED = 31
};

#endif


static FontColor m_fontColor;

class Util {
public:
	Util();

	static void log(const std::string, ...);
	static void warn(const std::string, ...);
	static void err(const std::string, ...);
private:
	static void Format(const char*, std::string, int, va_list, bool isfull = false);
};

#endif